/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Component } from 'react';
import { Modal, Button, Spin } from 'antd';
import styles from './index.less';
import classNames from 'classnames';

class KbModal extends Component {
  render() {
    const {
      okText = '确定',
      cancelText = '',
      okButtonProps = null,
      cancelButtonProps = null,
      children,
      className,
      loading,
      ...restProps
    } = this.props;
    return (
      <>
        <Modal
          footer={null}
          centered
          {...restProps}
          loading
          className={classNames(styles.modal, className)}
        >
          <Spin spinning={!!loading}>
            {children}
            {(cancelText || okText) && (
              <div className={styles.button}>
                {cancelText && (
                  <Button
                    size="large"
                    type="default"
                    onClick={this.props.onCancel}
                    {...cancelButtonProps}
                  >
                    {cancelText}
                  </Button>
                )}
                {okText && (
                  <Button size="large" type="primary" onClick={this.props.onOk} {...okButtonProps}>
                    {okText}
                  </Button>
                )}
              </div>
            )}
          </Spin>
        </Modal>
      </>
    );
  }
}

export default KbModal;
